<template>
  <!-- STP关键字新增-->
  <el-dialog
    :title="title"
    center
    :visible.sync="openState"
    width="1024px"
    :close-on-click-modal="false"
    :before-close="handleClose"
    append-to-body
  >
    <el-form ref="keywordForm" :model="keywordForm" :rules="rules" label-width="110px">
      <!--STP关键字新增-->
      <el-card class="form-card TechPara-card">
        <div slot="header" class="label-header-msg">
          <span>non-STP关键字新增</span>
        </div>

        <el-row>
          <el-col :span="12">
            <el-form-item label="报文类型" prop="pkgno">
              <el-select style="width: 100%" v-model="keywordForm.pkgno" placeholder="报文类型" @change="pkgnoChange">
                <el-option
                  v-for="dict in dictMap.STP_PKGNO"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="校验字段" prop="field">
              <el-select v-model="keywordForm.field" placeholder="校验字段">
                <el-option
                  v-for="dict in fieldList"
                  :key="dict.value"
                  :label="`${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="检验方式" prop="keystyle">
              <el-select style="width: 100%" v-model="keywordForm.keystyle" placeholder="检验方式">
                <el-option
                  v-for="dict in dictMap.KEYSTYLE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="关键字" prop="keyword">
              <el-input v-model="keywordForm.keyword" placeholder="关键字" />
            </el-form-item>
          </el-col>
        </el-row>



        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="remark">
              <el-input type="textarea" v-model="keywordForm.remark" placeholder="备注" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="来往账标志" prop="drct">
              <el-select v-model="keywordForm.drct" placeholder="来往账标志" style="width: 100%" :disabled="true">
                <el-option
                  v-for="dict in dictMap.DRCTCODE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="save">提 交</el-button>
      <el-button type="primary" @click="reset">重 置</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { keywordAdd } from "@/api/cnaps/bizMng/stpInstall.js";
import { listPageMixin } from "@/libs/listPageMixin";

export default {
  name: "keywordAddDialog",
  mixins: [listPageMixin],
  components: {},

  data() {
    return {
      title: "",
      // 是否显示弹出层
      openState: false,
      // 字段可编辑控制

      fieldList:[],
      isEdit: false,
      //数据字典
      searchFormDictList: ["DRCTCODE","KEYSTYLE","STP_PKGNO"],
      // 表单参数
      keywordForm: {},
      // 表单校验
      rules: {
        keyword: [{ required: true, message: "请输入关键字", trigger: "blur" }],
        pkgno: [{ required: true, message: "请选择报文类型", trigger: "blur" }],
        drct: [{ required: true, message: "请选择来往账方向", trigger: "blur" }],
        field:[{ required: true, message: "请选择校验字段", trigger: "blur" }],
        keystyle:[{ required: true, message: "请选择校验方式", trigger: "blur" }],
      },
      opButtonList: () => {
        return [];
      },
    };
  },
  mounted() {},
  methods: {

    pkgnoChange(code) {
      //联动修改bizCtgyCode
      let dictKeyPre = `STP_FIELD_${code.toUpperCase()}`;
      this.getDicts(dictKeyPre).then((response) => {
        this.fieldList = response.result;
        //修改控制下拉框处理
        if (!this.isEdit) {
          this.$set(this.keywordForm, "field", this.fieldList[0].value);
        }
        this.isEdit = false;
      });
    },
    // 表单重置
    reset() {
      this.resetForm("keywordForm");
      const drct = this.keywordForm.drct;
      this.$set(this, "keywordForm", {});
      this.fieldList = [];
      this.$set(this.keywordForm, "drct", drct);
    },
    // 关闭回掉
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          this.reset();
          done();
        })
        .catch((_) => {});
    },
    show(drct,nstpType) {
      this.title = "non-STP关键字新增";
      this.openState = true;
      this.keywordForm.drct = drct;
      this.keywordForm.nstpType = nstpType;
    },

    /** TODO提交按钮 */
    save() {
      this.$refs["keywordForm"].validate((valid) => {
        if (valid) {
          keywordAdd(this.keywordForm).then((res) => {
            if (res.code === "S") {
              this.msgSuccess("提交成功");
              this.cancel();
            }
          });
        }
      });
    },

    cancel() {
      this.reset();
      this.openState = false;
      this.$emit("editComplete", true);
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
